package panel.viewSpots.navigationNew
{
	import assists.HtmlText;
	import assists.Lang;
	import assists.TextFieldUtils;
	import assists.URI;
	import assists.media.SoundMedia;
	import assists.resource.ResourceLoader;
	
	import flash.desktop.NotificationType;
	import flash.display.Bitmap;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import inerface.INavigationTypeChoose;
	
	public class NavigationTypeChoose extends Sprite implements INavigationTypeChoose
	{
		private var _titleTxt:TextField = new TextField();
		private var _descTxt:TextField = new TextField();
		private var _setOutBtn:Sprite = new Sprite();
		private var _downBack:Shape = new Shape();

		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		private var _uri:URI;
		private var _clickBtn:RadionBtnClouree;
		
		public static const TYPE_NORMAL:int = 1;
		public static const TYPE_SPEED:int = 2;
		public static const TYPE_CAR:int = 3;

		private var _pathPanel:NavigationPathPanel;

		private var _topBack:Bitmap;
		private var _topBtnList:Array = [];
		private var _musicFunc:Function;
		private var _soundMedia:SoundMedia;
		private var _openDetailFunc:Function;
		private var _weiboFunc:Function;
		private var _data:Object;
		public function NavigationTypeChoose()
		{
			super();
		}
		
		public function onFunc(...args):void
		{
			_musicFunc = args[0];
			_openDetailFunc = args[1];
			_weiboFunc = args[2];
		}
		
		public function init(stage:Stage,loader:ResourceLoader,lang:Lang,uri:URI = null):void
		{
			_stage = stage;
			_loader = loader;
			_lang = lang;
			_uri = uri;
			
			_setOutBtn.addChild(new _loader.uiManager.setoutPng());
			_downBack.graphics.beginFill(0x0099ff,0.5);
			_downBack.graphics.drawRect(0,0,_stage.stageWidth,_stage.stageHeight * 0.2);
			_downBack.graphics.endFill();
			_setOutBtn.width = _setOutBtn.height = _downBack.width * 0.2;
			_descTxt.mouseEnabled = false;
			_descTxt.width = _downBack.width * 0.7;
			_descTxt.height = _downBack.height;
			_descTxt.multiline = true;
			_descTxt.wordWrap = true;
			
			_titleTxt.mouseEnabled = false;
			_titleTxt.autoSize = "left";
			TextFieldUtils.setHtmlText(_titleTxt,HtmlText.formatSizeColor("请选择您的游览模式",0xffffff,24));
			_titleTxt.x = (_stage.stageWidth - _titleTxt.width) * 0.5;
			
			_topBack = new _loader.uiManager.topBackPng();
			_topBack.width = _stage.stageWidth + 6;
			_topBack.height = _stage.stageHeight * 0.15;
			
			_setOutBtn.addEventListener(MouseEvent.CLICK,clickSetOutHandler);
			
			layout();
			this.addChild(_topBack);
			this.addChild(_downBack);
			this.addChild(_setOutBtn);
			this.addChild(_descTxt);
			this.addChild(_titleTxt);
		}
		
		protected function clickSetOutHandler(event:MouseEvent):void
		{
			this.removeChild(_topBack);
			this.removeChild(_downBack);
			this.removeChild(_setOutBtn);
			this.removeChild(_descTxt);
			this.removeChild(_titleTxt);
			var radioBtn:RadionBtnClouree;
			for(var i:int=0;i<_topBtnList.length;i++)
			{
				radioBtn = _topBtnList[i];
				this.removeChild(radioBtn);
			}
			_pathPanel.showNormal();
		}
		
		private function layout():void
		{
			_downBack.y = _stage.stageHeight - _downBack.height;
			_descTxt.y = _downBack.y;
			_setOutBtn.y = _downBack.y + (_downBack.height - _setOutBtn.height) * 0.5;
			_setOutBtn.x = _stage.stageWidth - _setOutBtn.width * 1.2;
			
		}
		
        public function show(data:Object,map:Bitmap):void
		{
			_data = data;
			if(data.speedPath.path.length > 1)
			{
				var speedBtn:RadionBtnClouree = new RadionBtnClouree(_loader);
				speedBtn.btnType = TYPE_SPEED;
				speedBtn.show(clickRadioBtn,HtmlText.formatSizeColor("快速浏览",0xffffff),RadionBtnClouree.TYPE_OVER);
				_topBtnList.push(speedBtn);
			}
			if(data.normalPath.path.length > 1)
			{
				var normalPath:RadionBtnClouree = new RadionBtnClouree(_loader);
				normalPath.btnType = TYPE_NORMAL;
				normalPath.show(clickRadioBtn,HtmlText.formatSizeColor("标准浏览",0xffffff),RadionBtnClouree.TYPE_CLICK);
				_topBtnList.push(normalPath);
			}
			if(data.carPath.path.length > 1)
			{
				var carBtn:RadionBtnClouree = new RadionBtnClouree(_loader);
				carBtn.show(clickRadioBtn,HtmlText.formatSizeColor("自驾游览",0xffffff),RadionBtnClouree.TYPE_OVER);
				carBtn.btnType = TYPE_CAR;
				_topBtnList.push(carBtn);
			}
			var radioBtn:RadionBtnClouree;
			for(var i:int=0;i<_topBtnList.length;i++)
			{
				radioBtn = _topBtnList[i];
				radioBtn.Wid = _stage.stageWidth * 0.25;
				radioBtn.y = _titleTxt.y + _titleTxt.height;
				radioBtn.x = (_stage.stageWidth - _topBtnList.length * radioBtn.width) * 0.5 + radioBtn.width * i;
				radioBtn.addEventListener(MouseEvent.CLICK,clickRadioHandler);
				this.addChild(radioBtn);
			}
			_clickBtn = normalPath;
			TextFieldUtils.setHtmlText(_descTxt,HtmlText.formatSizeColor(data.normalPath.desc,0xffffff,22));
			_pathPanel = new NavigationPathPanel(_stage,_loader,data,map);
			if(_clickBtn == null)
			{
				TextFieldUtils.setHtmlText(_titleTxt,HtmlText.formatSizeColor("暂无景点路线数据",0xffffff,24));
				_pathPanel.show(0);
			}else
			{
			_pathPanel.show(_clickBtn.btnType);
			}
			_pathPanel.onFunc(_musicFunc,_openDetailFunc,_weiboFunc);
			this.addChildAt(_pathPanel,0);
		}
		
		protected function clickRadioHandler(event:MouseEvent):void
		{
			var btn:RadionBtnClouree = event.currentTarget as RadionBtnClouree;
 			if(_clickBtn == null)
			{
				_clickBtn = btn;
			}else if(_clickBtn == btn)
			{
				return;
			}
			_clickBtn.changeState(false);
			_clickBtn = btn;
			_clickBtn.changeState(true);
			_pathPanel.changePath(_clickBtn.btnType);
			if(_clickBtn.btnType == TYPE_CAR)
			{
				TextFieldUtils.setHtmlText(_descTxt,HtmlText.formatSizeColor(_data.carPath.desc,0xffffff,22));
			}else if(_clickBtn.btnType == TYPE_NORMAL)
			{
				TextFieldUtils.setHtmlText(_descTxt,HtmlText.formatSizeColor(_data.normalPath.desc,0xffffff,22));
			}else if(_clickBtn.btnType == TYPE_SPEED)
			{
			TextFieldUtils.setHtmlText(_descTxt,HtmlText.formatSizeColor(_data.speedPath.desc,0xffffff,22));
			}
		}
		
		public function set onSoundMedia(value:SoundMedia):void
		{
			if(_soundMedia) return;
			_soundMedia = value;
			_pathPanel.onSoundMedia = value;
		}
		
		private function clickRadioBtn(type:int):void
		{
			
		}
		
		public function clear():void
		{
			
		}
		
	}
}